package com.his.controller;


import com.his.dto.PrescriptionInsert;
import com.his.entity.MedicinePrescriptionRecord;
import com.his.entity.ResponseResult;
import com.his.service.IMedicinePrescriptionRecordService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 * 成药处方表 前端控制器
 * </p>
 *
 * @author Demoon Liu
 * @since 2022-02-20
 */
@RestController
@RequestMapping("/medicine-prescription-record")
@Tag(name = "药品处方管理模块接口")
public class MedicinePrescriptionRecordController {

    @Resource
    private IMedicinePrescriptionRecordService service;

    @PostMapping("insert")
    @Operation(summary = "新增处方", description = "包含一个药品处方对象和一个药品数组")
    @ApiResponses(value = {
            @ApiResponse(responseCode = "201", description = "返回201，插入成功"),
            @ApiResponse(responseCode = "400", description = "返回400，插入失败"),
    })
    public ResponseResult insert(@RequestBody PrescriptionInsert prescriptionInsert) {
        return service.myInsert(prescriptionInsert);
    }

    @PostMapping("delete")
    @Operation(summary = "根据id删除药品处方信息", description = "需要管理员权限，id是必要参数")
    @ApiResponses(value = {
            @ApiResponse(responseCode = "201", description = "返回201，删除成功"),
            @ApiResponse(responseCode = "400", description = "返回400，删除失败"),
    })
    public ResponseResult delete(@RequestBody MedicinePrescriptionRecord medicinePrescriptionRecord) {
        return service.myDelete(medicinePrescriptionRecord);
    }

    @PostMapping("search-by-id")
    @Operation(summary = "根据药品处方id查询药品处方信息", description = "id是必要参数")
    @ApiResponses(value = {
            @ApiResponse(responseCode = "201", description = "返回201，查询成功和药品处方信息"),
            @ApiResponse(responseCode = "400", description = "返回400，查询失败"),
    })
    public ResponseResult searchById(@RequestBody MedicinePrescriptionRecord medicinePrescriptionRecord) {
        return service.mySearchById(medicinePrescriptionRecord);
    }

    @PostMapping("search-by-registration-id")
    @Operation(summary = "根据诊断id查询药品处方信息", description = "诊断id是必要参数")
    @ApiResponses(value = {
            @ApiResponse(responseCode = "201", description = "返回201，查询成功和药品处方信息"),
            @ApiResponse(responseCode = "400", description = "返回400，查询失败"),
    })
    public ResponseResult searchByRegistrationId(@RequestBody MedicinePrescriptionRecord medicinePrescriptionRecord) {
        return service.mySearchByRegistrationId(medicinePrescriptionRecord);
    }


}
